package jmu.edu.yjc.service.impl;

import jmu.edu.yjc.Utils.SecurityUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
@Service("ps")
public class PermissionService {
    /**
     * 判断当前用户是否有权限
     * @param permission 需要判断的权限
     * @return
     */
    public boolean hasPermission(String permission){
        //如果是超级管理员直接返回true
        if(SecurityUtil.isAdmin()){
            return true;
        }
        //否则判断当前用户的权限是否拥有permission
        List<String> permissions = SecurityUtil.getLoginUser().getPermissions();
        if(Objects.isNull(permissions)){
            return false;
        }
        return permissions.contains(permission);
    }
}
